package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyCommentService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/strategies")
public class StrategyController {

    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService catalogService;
    @Autowired
    private IStrategyDetailService detailService;
    @Autowired
    private IStrategyCommentService commentService;

    /**
     * 获取状态为推荐的所有攻略资源-app推荐
     *
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo query(StrategyQueryObject qo) {
        return strategyService.query(qo);
    }

    /**
     * 根据攻略id查询大攻略资源-title
     */
    @GetMapping("/{id}")
    public Strategy getById(@PathVariable Long id) {
        return strategyService.getById(id);
    }

    /**
     * 根据攻略id查询攻略catalog分类集合资源
     *
     * @return
     */
    @GetMapping("/{id}/catalogs")
    public List<StrategyCatalog> listByStrategyId(@PathVariable Long id) {
        return catalogService.listByStrategyId(id);

    }

    /**
     * 根据攻略文章id查询文章内容
     *
     * @return
     */
    @GetMapping("/details/{id}")
    public StrategyDetail getByDetailId(@PathVariable Long id) {
        return detailService.getByDetailId(id);
    }

    /**
     * 根据攻略id查询所有的评论
     *
     * @return pageInfo
     */
    @GetMapping("/{strategyId}/comments")
    public PageInfo listCommentByStrategyId(StrategyCommentQueryObject qo) {
        qo.setOrderBy("sc.createTime desc");
        return commentService.listCommentByStrategyId(qo);
    }

    /**
     * 获取前六个标签
     * @param qo
     * @return
     */
    @GetMapping("/{strategyId}/tags")
    public PageInfo listTagsByStrategyId(StrategyCommentQueryObject qo) {
        qo.setPageSize(6);
        return commentService.listTagsByStrategyId(qo);
    }

    /**
     * 为指定的攻略新增点评信息
     */
    @PostMapping("/{strategy.id}/comments")
    public JsonResult save(StrategyComment strategyComment, String[] tags) {
        commentService.save(strategyComment,tags);
        return new JsonResult();
    }



}
